﻿using System.Collections.Generic;
using System.Data;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RayD.Core;
using RayD.App.SystemModule;
using RayD.WebApi.Models.Admin;
using RayD.Repository;

namespace RayD.WebApi.Controllers.Admin
{
    /// <summary>
    /// 信息监控资源
    /// </summary>
    public class MonitorController : BaseAdminController
    {
        #region 构造函数注入
        private MonitorApp _Monitor;
        public MonitorController(MonitorApp monitor)
        {
            this._Monitor = monitor;
        }
        #endregion

        #region 获取数据
        /// <summary>
        /// 获取实时调度数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResParameter<VchartRespone> GetApiByDay()
        {
            var data = _Monitor.GetApiByTimeType(TimeType.Day);
            List<string> columns = new List<string>();
            foreach (DataColumn column in data.Columns)
            {
                columns.Add(column.ColumnName);
            }
            return Success(new VchartRespone()
            {
                columns = columns,
                rows = data
            });
        }
        /// <summary>
        /// 获取本周调度数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResParameter<VchartRespone> GetApiByWeek()
        {
            var data = _Monitor.GetApiByTimeType(TimeType.Week);
            List<string> columns = new List<string>();
            foreach (DataColumn column in data.Columns)
            {
                columns.Add(column.ColumnName);
            }
            return Success(new VchartRespone()
            {
                columns = columns,
                rows = data
            });
        }
        /// <summary>
        /// 获取本月调度数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResParameter<VchartRespone> GetApiByMonth()
        {
            var data = _Monitor.GetApiByTimeType(TimeType.Month);
            List<string> columns = new List<string>();
            foreach (DataColumn column in data.Columns)
            {
                columns.Add(column.ColumnName);
            }
            return Success(new VchartRespone()
            {
                columns = columns,
                rows = data
            });
        }
        /// <summary>
        /// 获取本年调度数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResParameter<VchartRespone> GetApiByYear()
        {
            var data = _Monitor.GetApiByTimeType(TimeType.Year);
            List<string> columns = new List<string>();
            foreach (DataColumn column in data.Columns)
            {
                columns.Add(column.ColumnName);
            }
            return Success(new VchartRespone()
            {
                columns = columns,
                rows = data
            });
        }
        #endregion
    }

}
